package com.ruoyi.web.controller.cinema;

import com.ruoyi.cinema.domain.Area;
import com.ruoyi.cinema.service.IAreaService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.FrontTreeObj;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.TreeUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 区域Controller
 *
 * @author HHAOYU
 * @date 2020-12-07
 */
@RestController
@RequestMapping("/cinema/area")
public class AreaController extends BaseController
{
    @Autowired
    private IAreaService areaService;

    /**
     * 查询区域列表
     */
    @PreAuthorize("@ss.hasPermi('cinema:area:list')")
    @GetMapping("/list")
    public AjaxResult list(Area area)
    {
        List<Area> list = areaService.selectAreaList(area);
        return AjaxResult.success(list);
    }

    @GetMapping("/treeselect")
    public AjaxResult treeselect(Area area)
    {
        List<FrontTreeObj> frontTreeObjList = areaService.selectAreaListForTreeSelect(area);
        return AjaxResult.success(TreeUtils.buildTreeSelect(frontTreeObjList));
    }

    /**
     * 导出区域列表
     */
    @PreAuthorize("@ss.hasPermi('cinema:area:export')")
    @Log(title = "区域", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Area area)
    {
        List<Area> list = areaService.selectAreaList(area);
        ExcelUtil<Area> util = new ExcelUtil<Area>(Area.class);
        return util.exportExcel(list, "area");
    }

    /**
     * 获取区域详细信息
     */
    @PreAuthorize("@ss.hasPermi('cinema:area:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(areaService.selectAreaById(id));
    }



    /**
     * 新增区域
     */
    @PreAuthorize("@ss.hasPermi('cinema:area:add')")
    @Log(title = "区域", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Area area)
    {
        return toAjax(areaService.insertArea(area));
    }

    /**
     * 修改区域
     */
    @PreAuthorize("@ss.hasPermi('cinema:area:edit')")
    @Log(title = "区域", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Area area)
    {
        return toAjax(areaService.updateArea(area));
    }

    /**
     * 删除区域
     */
    @PreAuthorize("@ss.hasPermi('cinema:area:remove')")
    @Log(title = "区域", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(areaService.deleteAreaByIds(ids));
    }
}
